package org.peterf.foxish.engine.input;

import org.peterf.foxish.engine.Engine;

import android.view.MotionEvent;

public class FingerEvent {

    private Engine engine;

    private MotionEvent event;

    public FingerEvent(Engine engine) {
        this.engine = engine;
    }

    public int findPointerIndex(int pointerId) {
        return event.findPointerIndex(pointerId);
    }

    public int getActionIndex() {
        return event.getActionIndex();
    }

    public int getActionMasked() {
        return event.getActionMasked();
    }

    public long getEventTime() {
        return event.getEventTime();
    }

    public float getHistoricalPressure(int pointerIndex, int pos) {
        return event.getHistoricalPressure(pointerIndex, pos);
    }

    public float getHistoricalX(int pointerIndex, int pos) {
        // TODO Caches the transformed coordinates for frequent requests.
        return engine.getCamera().stdToWorldX(
                engine.getScreenSetting().screenToStdX(
                        event.getHistoricalX(pointerIndex, pos)));
    }

    public float getHistoricalY(int pointerIndex, int pos) {
        // TODO Caches the transformed coordinates for frequent requests.
        return engine.getCamera().stdToWorldY(
                engine.getScreenSetting().screenToStdY(
                        event.getHistoricalY(pointerIndex, pos)));
    }

    public int getHistorySize() {
        return event.getHistorySize();
    }

    public int getPointerCount() {
        return event.getPointerCount();
    }

    public int getPointerId(int pointerIndex) {
        return event.getPointerId(pointerIndex);
    }

    public float getPressure(int pointerIndex) {
        return event.getPressure(pointerIndex);
    }

    public float getX(int pointerIndex) {
        // TODO Caches the transformed coordinates for frequent requests.
        return engine.getCamera().stdToWorldX(
                engine.getScreenSetting()
                        .screenToStdX(event.getX(pointerIndex)));
    }

    public float getY(int pointerIndex) {
        // TODO Caches the transformed coordinates for frequent requests.
        return engine.getCamera().stdToWorldY(
                engine.getScreenSetting()
                        .screenToStdY(event.getY(pointerIndex)));
    }

    public void wrap(MotionEvent event) {
        this.event = event;
    }

}
